package com.mmall.controller.portal;

import com.github.pagehelper.PageInfo;
import com.mmall.common.ServerResponse;
import com.mmall.service.ICategoryService;
import com.mmall.service.IProductService;
import com.mmall.vo.ProductDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

	@Autowired
	private IProductService iProductService;
	@Autowired
	private ICategoryService categoryService;



	@RequestMapping("detail.do")
	public ServerResponse<ProductDetailVo> detail(Integer productId){
		return iProductService.getProductDetail(productId);
	}

	@RequestMapping("list.do")
	public ServerResponse<PageInfo> list(@RequestParam(value = "keyword",required = false)String keyword,
										 @RequestParam(value = "categoryId",required = false)Integer categoryId,
										 @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
										 @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
										 @RequestParam(value = "orderBy",defaultValue = "") String orderBy){
		return iProductService.getProductByKeywordCategory(keyword,categoryId,pageNum,pageSize,orderBy);
	}

	@RequestMapping("get_all_category.do")
	public ServerResponse getAllCategory(){
		return categoryService.getCategoryTree();
	}
}
